//exception from destructor
#include <iostream>
#include <exception>
using namespace std;

class A{
public:
  A(){cout<<"A()"<<endl;}
  ~A();
};
A::~A()
{//necessary
  try{
    cout<<"~A()\t"<<boolalpha<<uncaught_exception()<<endl;
    int i = 1;
    throw i;
  }
  catch(int i){
    cout<<"caught in ~A()"<<endl;
  }
}//necessary


void foo()
{
 
  A a;
  throw 12;
  cout<<"after thrown in foo()"<<endl;

}

int main()
{
  try {
  
    foo();
  }
  catch(int i) {
    cout<<"caught in main()\t"<<i<<endl;
  }
  return 0;
}
